package com.auxgroup.hr.front.site.co.personnel;

import java.math.BigDecimal;
import java.util.List;
import java.util.stream.Collector;
import java.util.stream.Collectors;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.auxgroup.hr.front.commons.vo.BaseResponseVO;
import com.auxgroup.hr.front.dao.domain.PsCPersonalInfoClass;
import com.auxgroup.hr.front.dao.domain.PsCWorkhisTbl;
import com.auxgroup.hr.front.dozer.IObjectMapper;
import com.auxgroup.hr.front.service.personnal.WorkhisService;
import com.auxgroup.hr.front.site.co.BaseCO;

/**
 * 工作历史信息CO
 * @author lvliuhao
 * @version 创建时间：180526 
 */
@RestController
@RequestMapping("${auxgroup.hr.contextPath}/workhis")
public class WorkhisCO extends BaseCO {

	private static final Logger logger = LoggerFactory.getLogger(WorkhisCO.class);

	@Autowired
	public WorkhisService workhisService;

	@Resource(name = "dozerMapper")
	protected IObjectMapper objectMapper;

	/**
	 * 根据用户id 获取用户的所有工作经历
	 * @param emplid
	 * @return
	 */
	@GetMapping(value = "/getAll")
	public BaseResponseVO getAll(String emplid){
		logger.info("getWorkhis param= {}", emplid);
		List<PsCWorkhisTbl> list = workhisService.getAll(emplid);
		return buildRespone(list.stream().filter(t -> !"100".equals(t.getcExpWorkType())).collect(Collectors.toList()));
	}
	
	/**
	 * 根据用户id 和 工作经历的序号查询某一条工作经历信息
	 * @param hireId
	 * @return
	 */
	@GetMapping(value = "/getOne")
	public BaseResponseVO getOne(String emplid,BigDecimal cSeqno) {
		logger.info("getWorkhis param= {}", emplid);
		PsCPersonalInfoClass personalInfoClass = new PsCPersonalInfoClass(emplid,cSeqno);
		PsCWorkhisTbl workhis = workhisService.getWorkhis(personalInfoClass);
		return buildRespone(workhis);
	}
	
	/**
	 * 获取入职后的工作经历
	 * @return
	 */
	@GetMapping(value="/getNowWorkHis")
	public BaseResponseVO getNowWorkHis(String emplid){
		logger.info("getNowWorkHi param= {}", emplid);
		return buildRespone(workhisService.getNowWorkHis(emplid),false);
	}
	
}
